//
//  IMenu.m
//  XRmenu
//
//  Created by yangxh on 11-3-26.
//  Copyright 2011 E0571. All rights reserved.
//

#import "IMenu.h"


@implementation IMenu

@synthesize checkInTime;
@synthesize departmentId;
@synthesize Id;
@synthesize menuId;
@synthesize name;
@synthesize productsCount;
@synthesize status;

//=========================================================== 
// - (id)init
//
//=========================================================== 
- (id)init
{
	return [self initWithCheckInTime:nil departmentId:0 Id:0 menuId:nil name:nil productsCount:0 status:0];
}


//=========================================================== 
// - (id)initWith:
//
//=========================================================== 
- (id)initWithCheckInTime:(NSDate*)aCheckInTime departmentId:(NSInteger)aDepartmentId Id:(NSInteger)anId menuId:(NSString*)aMenuId name:(NSString*)aName productsCount:(NSInteger)aProductsCount status:(NSInteger)aStatus 
{
    self = [super init];
    if (self) {
        self.checkInTime = aCheckInTime;
        self.departmentId = aDepartmentId;
        self.Id = anId;
        self.menuId = aMenuId;
        self.name = aName;
        self.productsCount = aProductsCount;
        self.status = aStatus;
    }
    return self;
}


//=========================================================== 
// + (id)objectWith:
//
//=========================================================== 
+ (id)objectWithCheckInTime:(NSDate*)aCheckInTime departmentId:(NSInteger)aDepartmentId Id:(NSInteger)anId menuId:(NSString*)aMenuId name:(NSString*)aName productsCount:(NSInteger)aProductsCount status:(NSInteger)aStatus  
{
    id result = [[[self class] alloc] initWithCheckInTime:aCheckInTime departmentId:aDepartmentId Id:anId menuId:aMenuId name:aName productsCount:aProductsCount status:aStatus];
	
    return [result autorelease];
}

//=========================================================== 
// - (NSArray *)keyPaths
//
//=========================================================== 
- (NSArray *)keyPaths
{
    NSArray *result = [NSArray arrayWithObjects:
					   @"checkInTime",
					   @"departmentId",
					   @"Id",
					   @"menuId",
					   @"name",
					   @"productsCount",
					   @"status",
					   nil];
	
    return result;
}


//=========================================================== 
// - (NSString *)descriptionForKeyPaths
//
//=========================================================== 
- (NSString *)descriptionForKeyPaths 
{
    NSMutableString *desc = [NSMutableString string];
    NSEnumerator *e = [[self keyPaths] objectEnumerator];
    NSString *thisKey;
    [desc appendString:@"\n\n"];
	
    while ((thisKey = [e nextObject])) {
        [desc appendFormat: @"%@: %@\n", thisKey, [self valueForKey:thisKey]];
    }
	
    return [NSString stringWithString:desc];
}

- (NSString *)description
{
	return [self descriptionForKeyPaths];
}

//=========================================================== 
// dealloc
//=========================================================== 
- (void)dealloc
{
    [checkInTime release];
    checkInTime = nil;
    [menuId release];
    menuId = nil;
    [name release];
    name = nil;
	
    [super dealloc];
}

+ (IMenu *)iMenuByParse:(NSDictionary *)info
{
	IMenu *menu = [IMenu objectWithCheckInTime:[NSDate date]
								  departmentId:dictInt(info,@"DepartmentID")
											Id:dictInt(info,@"ID")
										menuId:dictObject(info,@"MenuId")
										  name:dictObject(info,@"Name") 
								 productsCount:dictInt(info,@"ProductsCount")
										status:dictInt(info,@"Status")];
	return menu;
}

@end
